<?php
/**
 * +----------------------------------------------------------------------
 * | Copyright © Sogu Technologies Co. Ltd 2018-2050 All rights reserved.
 * +----------------------------------------------------------------------
 * | File name: CollectionRequest.php
 * +----------------------------------------------------------------------
 * | Author: lijiafei
 * +----------------------------------------------------------------------
 * | Description:
 * +----------------------------------------------------------------------
 * | Others: 其他内容的说明
 * +----------------------------------------------------------------------
 * | History:
 * +----------------------------------------------------------------------
 * | 1.Date: 2019/2/26 Author: lijiafei Modification: 创建
 * +----------------------------------------------------------------------
 */

namespace App\Library\Traits;


use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;

trait CollectionRequest
{

    public function request($url, $method = 'POST')
    {
        $client = new Client(['base_uri' => $this->collection_uri, 'timeout' => 30.0]);
        $this->body = [
            'orgCode' => $this->collection_org_code,
            'sign' => $this->_pub_sign,
            'reqData' => json_encode($this->_pub_data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),
        ];
        Log::debug('collection_request_data', ['body' => $this->body]);
        $result = $client->request($method, $url, ['json' => $this->body, 'verify' => false]);
        return json_decode($result->getBody()->getContents(), true);
    }

    /**一次性请求多个,催收系统优化
     * @param $url
     * @param string $method
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function requests($url, $method = 'POST')
    {
        $client = new Client(['base_uri' => $this->collection_uri, 'timeout' => 30.0]);
        $this->body = [
            'orgCode' => $this->collection_org_code,
            'sign' => $this->_pub_sign,
            'reqData' => $this->_pub_data,
        ];
        \Log::debug('催收系统请求数据:' . json_encode($this->body, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
        $result = $client->request($method, $url, ['json' => $this->body, 'verify' => false]);
        return json_decode($result->getBody()->getContents(), true);
    }

}